//
//  CTVHTTPResourceDownload.h
//  Channltv
//
//  Created by Bruno Keymolen on 04/09/07.
//  Copyright 2007 channl.tv. All rights reserved.
//
//  downloads resource data (jpg etc) to the cache /Resource/ slot


#import <Cocoa/Cocoa.h>


@class CTVResourceDownloadReply, CTVHTTPResourceDownload;

@protocol CTVResourceDownloadReply
	-(int)finishResourceDownload:(CTVHTTPResourceDownload*)resourceDownload;
	-(int)releaseResourceDownload:(CTVHTTPResourceDownload*)resourceDownload;
@end

@interface CTVHTTPResourceDownload : NSObject {
	CTVResourceDownloadReply* m_resourceReply;
	NSString* m_url;
	NSString* m_cachePath;
	NSURLConnection* m_connection;	
	NSMutableData* m_data;
	int m_httpStatusCode;
}

-(id)initWithURLString:(NSString*)urlstring andResourceReply:(CTVResourceDownloadReply*)resourceReply;
-(void)dealloc;
-(int)cache;
-(NSString*)cachePath;
-(NSString*)urlString;
-(int)httpStatusCode;

/* NSURLConnection Delegates */
- (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse;
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;


@end
